using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Collections.Specialized;
using System.Net;

namespace CustomCMS.QA
{
	class Util
	{
		const string C_SERVER_URL = "http://localhost:3067/Interface/default.aspx";

		public static void VerifyResult(XmlDocument doc, string expected) 
		{ 
			XmlNode resultNode = doc.FirstChild.NextSibling; 
			
			if (resultNode.Name != "result") 
				throw new Exception("unexpected xml structure"); 
			
			NUnit.Framework.Assert.AreEqual(expected, resultNode.Attributes["status"].Value, resultNode.InnerText); 
		}  
		
		public static XmlDocument ExecuteWebRequest(NameValueCollection data) 
		{ 
			WebClient cli = new WebClient(); 
			byte[] buffer = cli.UploadValues(C_SERVER_URL, data); 
			string result = System.Text.Encoding.UTF8.GetString(buffer); 
			System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); 
			doc.LoadXml(result); return doc; 
		}
	}
}
